{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "n, x = 5, 8\n",
    "fans_counts = [1, 2, 3, 4, 10]\n",
    "\n",
    "fans_counts.sort(reverse=True)\n",
    "fans_counts__recommend = [i // 2 for i in fans_counts]\n",
    "\n",
    "total_recommendations = 0\n",
    "new_fans = 0\n",
    "for i in range(n):\n",
    "    new_fans += fans_counts__recommend[i]\n",
    "    total_recommendations += 1\n",
    "    if new_fans >= x:\n",
    "        print(total_recommendations)\n",
    "        break\n",
    "else:\n",
    "    print(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.3333333333\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "Format specifier missing precision",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[14], line 5\u001b[0m\n\u001b[0;32m      2\u001b[0m p\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m\u001b[38;5;241m/\u001b[39mn\u001b[38;5;241m/\u001b[39m(n\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mround\u001b[39m(p,\u001b[38;5;241m10\u001b[39m))\n\u001b[1;32m----> 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m{\u001b[39;49m\u001b[38;5;124;43m:.f10}\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mformat\u001b[49m\u001b[43m(\u001b[49m\u001b[43mp\u001b[49m\u001b[43m)\u001b[49m)\n",
      "\u001b[1;31mValueError\u001b[0m: Format specifier missing precision"
     ]
    }
   ],
   "source": [
    "n =3\n",
    "p=2/n/(n-1)\n",
    "\n",
    "print(round(p,10))\n",
    "print(\"{:.f10}\".format(p))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "([10, 4, 3, 2, 1], [5, 2, 1, 1, 0])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n, x = 5, 8\n",
    "fans_counts = [1, 2, 3, 4, 10]\n",
    "fans_counts.sort(reverse=True)\n",
    "fans_counts__recommend = [i//2 for i in fans_counts]\n",
    "fans_counts, fans_counts__recommend\n",
    "# 在降序数组fans_counts和fans_counts__recommend中，找若干数相加，使其结果等于x。注意，这些数的下标不能下标不能相同。求数的个数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n, x = 5,8 # 输入小苯的旧账号个数和新账号想要的粉丝数\n",
    "fans_counts = [1,2,3,4,10]  # 输入每个旧账号的粉丝数\n",
    "# n, x = map(int, input().split())  # 输入小苯的旧账号个数和新账号想要的粉丝数\n",
    "# fans_counts = list(map(int, input().split()))  # 输入每个旧账号的粉丝数\n",
    "\n",
    "total_fans = sum(fans_counts)  # 计算所有旧账号的粉丝数总和\n",
    "\n",
    "if total_fans < x:  # 如果总粉丝数已经<新账号想要的粉丝数\n",
    "    print(-1)  # 直接输出0，不需要再向任何旧账号发推荐文章\n",
    "else:\n",
    "    fans_counts.sort(reverse=True)  # 将旧账号的粉丝数按降序排序\n",
    "\n",
    "    num_recommendations = 0  # 初始化推荐文章数量\n",
    "    for i, fans in enumerate(fans_counts):\n",
    "        if fans >= x:  # 如果某个旧账号的粉丝数已经大于等于新账号想要的粉丝数\n",
    "            num_recommendations += 1  # 可以选择在该账号多次发推荐文章\n",
    "            break\n",
    "        elif fans < x:  # 如果粉丝数小于新账号想要的粉丝数\n",
    "            x -= fans // 2  # 更新新账号还需要的粉丝数\n",
    "            num_recommendations += 1  # 推荐文章数量加1\n",
    "\n",
    "            if x <= 0:  # 如果新账号的粉丝数已经达到或超过要求\n",
    "                break\n",
    "\n",
    "    if x <= 0:  # 如果新账号的粉丝数已经达到或超过要求\n",
    "        print(num_recommendations)\n",
    "    else:  # 如果无法通过推荐使新账号的粉丝数达到要求\n",
    "        print(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5\n"
     ]
    }
   ],
   "source": [
    "n = int(input())\n",
    "\n",
    "# 计算碾压墙的概率\n",
    "probability = 2 * (1 / n) * (1 / n)\n",
    "\n",
    "print(round(probability, 10))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
